package skewreduce.framework.physical;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.Job;

import skewreduce.framework.EaggDriver;
import skewreduce.framework.EaggPlanCompiler;
import skewreduce.framework.SchedulerEvent;
import skewreduce.framework.logical.LogicalOp;


/**
 * maybe misleading naming since it does not do real optimization.
 * @author yongchul
 *
 */
public class PReoptimizeOp extends PhysicalOp {

	@Override
	public void setup() throws IOException {}
	
	@Override
	protected Job createJob(Configuration conf) throws IOException {
		throw new UnsupportedOperationException("REOPTIMIZE operator does not run a Map-Reduce job");
	}

	@Override
	public SchedulerEvent call() throws Exception {
		// at this point, our bound object should be expanded by the SAMPLE operator
		EaggPlanCompiler.compileRevisedPlan(plan,this);
        setStatus(Status.COMPLETE);
		return new SchedulerEvent.Completion(this);
	}
	
	public static LogicalOp createLogicalOp(EaggDriver driver) {
		return new LogicalOp(driver,LogicalOp.Type.REOPTIMIZE,0) {
			@Override
			public PhysicalOp createInstance() {
				return new PReoptimizeOp();
			}
		};
	}
}
